
// 安装列表管理
var Debit = Ext.data.Record.create([
	{name : 'id',mapping : 'id',type : 'int'}, 
	{name : 'pid',mapping : 'fid',type : 'int'}, 
	{name : 'buyer',mapping : 'buyer',type : 'string'}, 
	{name : 'unit',mapping : 'unit',type : 'string'}, 
	{name : 'mobile',mapping : 'mobile',type : 'string'}, 
	{name : 'phone',mapping : 'phone',type : 'string'}, 
	{name : 'address',mapping : 'address',type : 'string'}, 
	{name : 'csum',mapping : 'csum',type : 'float'},  
	{name : 'loanid',mapping : 'loanid',type : 'int'}, 
	{name : 'loanname',mapping : 'loanname',type : 'string'},  
	{name : 'rate',mapping : 'rate',type : 'float'}, 
	{name : 'interest',mapping : 'interest',type : 'float'},
	{name : 'charge',mapping : 'charge',type : 'float'},
	{name : 'debtorid',mapping : 'debtorid',type : 'int'},
	{name : 'debtorname',mapping : 'debtorname',type : 'string'},
	{name : 'startdate',mapping : 'startdate',type : 'date'},
	{name : 'closedate',mapping : 'closedate',type : 'date'},
	{name : 'accountid',mapping : 'accountid',type : 'int'},
	{name : 'accountname',mapping : 'accountname',type : 'string'},
	{name : 'status',mapping : 'status',type : 'string'},
	{name : 'createtime',mapping : 'createtime',type : 'string'},
	{name : 'memo',mapping : 'memo',type : 'string'}
	]);

var cm_debit = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), 
new Ext.grid.CheckboxSelectionModel({singleSelect : false}),
{
	header : '业务单据',
	width : 120,
	dataIndex : 'id'
},{
	header : '业务单位',
	width : 120,
	dataIndex : 'unit'
},{
	header : '用户姓名',
	width : 120,
	dataIndex : 'buyer'
},{
	header : '手机',
	width : 90,
	dataIndex : 'mobile'
},{
	header : '联系电话',
	width : 80,
	dataIndex : 'phone'
},{
	header : '用户地址',
	width : 90,
	dataIndex : 'address'
	
},{
	header : '单据日期',
	width : 90,
	dataIndex : 'closedate',
	renderer: renderDate,
	sortable:true
	
},{
	header : '贷款总额',
	width : 80,
	dataIndex : 'csum',
	sortable : false
},{
	header : '利率%',
	width : 60,
	dataIndex : 'rate',
	sortable : true
},{
	header : '利息支出',
	width : 60,
	dataIndex : 'interest',
	sortable : true
},{
	header : '投资费用',
	width : 60,
	dataIndex : 'charge',
	sortable : true
},{
	header : '状态',
	width : 60,
	dataIndex : 'status',
	sortable : true
},{
	header : '备注',
	width : 120,
	dataIndex : 'memo',
	sortable : true
}]);


var btn_add_debit = new Ext.Button({
	text : '增加贷款',
	iconCls : 'icon-add',
	handler : function() {
		window_add_debit.show();
	}
});

var btn_edit_debit = new Ext.Button({
	text : '修改贷款',
	iconCls : 'icon-edit',
	handler : function() {
		var record = grid_debit.getSelectionModel().getSelected();
		if (record) {
			if(record.data.status=="未还"){
				window_edit_debit.show();
			}else{
				Ext.Msg.show({title : '错误提示',
							msg : '这笔借款融资已结清或已部分还贷,不能修改!',
							buttons : Ext.Msg.OK,
							icon : Ext.Msg.ERROR
							});
			}
		}
	}
});

var btn_del_debit = new Ext.Button({
	text : '打印',
	iconCls : 'icon-del',
	handler : function() {
		var record = grid_debit.getSelectionModel().getSelected();
		if (record) {
		   
			openTab(record);
		}
	}
});

var btn_giveback_debit = new Ext.Button({
	text : '归还全部贷款',
	iconCls : 'icon-edit',
	handler : function() {
		var record = grid_debit.getSelectionModel().getSelected();
		if (record) {
			Ext.Msg.confirm('确认归还全部贷款', '你确定归还全部贷款?', function(btn) {
				if (btn == 'yes') {
					Ext.Ajax.request({
						url : app.url+'/admin/fix/fixList.do',
						params : {tid : record.data.tid},
						success : function() {ds_debit.load({params : {start : 0,limit : 20}});},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '归还时发生错误,这笔贷款已结清!',
								buttons : Ext.Msg.OK,
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			});
		}
	}
});

var btn_part_debit = new Ext.Button({
	text : '归还部分贷款',
	iconCls : 'icon-edit',
	width : 100,
	handler : function() {
		var record = grid_debit.getSelectionModel().getSelected();
		if (record) {
			if(record.data.status=="已结清"){
				Ext.Msg.show({title : '错误提示',
							msg : '这笔贷款已结清,不需要再还款!',
							buttons : Ext.Msg.OK,
							icon : Ext.Msg.ERROR
							});
			}else{
				window_part_debit.show();
				
			}
		}
	}
});


var text_search_debit = new Ext.form.TextField({
	name : 'textSearchDebit',
	width : 200,
	emptyText : '根据号码模糊查询!',
	listeners : {
		'specialkey' : function(field, e) {
			if (e.getKey() == Ext.EventObject.ENTER) {
				searchDebit();
			}
		}
	}
});

var awoke_search_debit = new Ext.form.ComboBox({
		mode : 'local',
		name : 'awokeDebit',
		editable : false,
		store : new Ext.data.SimpleStore({
			data : [['全部', 0],['十天内应还借款', 10], ['一月内应还借款',30],['两个月内应还借款',60],['半年内应还借款',120]],
			fields : ['text', 'value']
		}),
		displayField : 'text',
		valueField : 'value',
		hiddenName:'awokeDays',
		mode : 'local',
		triggerAction : 'all',
		emptyText : '全部应还借款',
		listeners : {
		'select' : function(combo, record, index) {
			ds_debit.baseParams.awokeDays = awoke_search_debit.getValue(); 
			ds_debit.baseParams.conditions = text_search_debit.getValue(); 
			ds_debit.load({params : {start : 0,limit : 20}});
		}
	}
});

var searchDebit = function() {
	ds_debit.baseParams.awokeDays = awoke_search_debit.getValue(); 
	ds_debit.baseParams.conditions = text_search_debit.getValue(); 
	ds_debit.load({params : {start : 0,limit : 20}});
}

var btn_search_debit = new Ext.Button({
	text : '查询',
	iconCls : 'icon-search',
	handler : searchDebit
});

var ds_debit = new Ext.data.Store({
	url : app.url+'/admin/fix/findList.do',
	reader : new Ext.data.JsonReader({totalProperty : 'totalProperty',root : 'root'}, 
	[{name : 'id',mapping : 'id',type : 'int'}, 
	{name : 'unit',mapping : 'unit',type : 'string'}, 
	{name : 'buyer',mapping : 'buyer',type : 'string'}, 
	{name : 'mobile',mapping : 'mobile',type : 'string'}, 
	{name : 'phone',mapping : 'phone',type : 'string'},  
	{name : 'address',mapping : 'address',type : 'string'}, 
	{name : 'loanname',mapping : 'loanname',type : 'string'},  
	{name : 'rate',mapping : 'rate',type : 'float'}, 
	{name : 'interest',mapping : 'interest',type : 'float'},
	{name : 'charge',mapping : 'charge',type : 'float'},
	{name : 'debtorid',mapping : 'debtorid',type : 'int'},
	{name : 'debtorname',mapping : 'debtorname',type : 'string'},
	{name : 'startdate',mapping : 'startdate',type : 'string'},
	{name : 'closedate',mapping : 'closedate',type : 'string'},
	{name : 'accountid',mapping : 'accountid',type : 'int'},
	{name : 'accountname',mapping : 'accountname',type : 'string'},
	{name : 'status',mapping : 'status',type : 'string'},
	{name : 'createtime',type : 'string'},
	{name : 'memo',type : 'string'}
	])
});

var grid_debit = new Ext.grid.EditorGridPanel({
	title : '安装列表',
	iconCls : 'icon-grid',
	loadMask : {msg : '数据加载中...'},
	collapsible: false,
    region: 'center',
    margins: '5 0 0 0',
	viewConfig:
	{
	 forceFit:true,
	 scrollOffset:15
	 },	   	   
	autoWidth : true,
	region : 'center',
	cm : cm_debit,
	ds : ds_debit,
	sm : new Ext.grid.CheckboxSelectionModel({singleSelect : false}),
	enableColumnMove : false,
	trackMouseOver : false,
	frame : true,
	clicksToEdit : 1,
	tbar : [btn_add_debit,btn_edit_debit, btn_del_debit,'-',btn_part_debit,btn_giveback_debit, '-',text_search_debit,'-',awoke_search_debit,'-',btn_search_debit],
	bbar : new Ext.PagingToolbar({
		pageSize : 20,
		store : ds_debit,
		displayInfo : true,
		displayMsg : '第 {0} - {1} 条  共 {2} 条',
		emptyMsg : "没有记录",
		items:[{   
                text: '导出到Excel',   
                tooltip: 'Excel',   
                handler: debitExport // 
                        }]
	}),listeners : {
		'click' : function(){
			var record = this.getSelectionModel().getSelected();
			tplin.overwrite(debit_Detail.body,record.data);
			ds_debit_data.baseParams.tid = record.data.tid; 
			ds_debit_data.load({params : {start : 0,limit : 1000}});
		}
	}
});

function openTab(record){
        //record = (record && record.data) ? record : this.gsm.getSelected();
        var d = record.data;
        var tab= new Ext.Panel({
                title: '详细内容',
				closable:true,
				toolTemplate:tplin
            });
        debit_tabs2.add(tab);
        debit_tabs2.setActiveTab(tab);
    }

function debitExport(){
	doExport(grid_debit);
}

var window_add_debit = new Ext.Window({
	title : '增加一笔贷款',
	width : 320,
	resizable : false,
	autoHeight : true,
	modal : true,
	closeAction : 'hide',
	listeners : {
		'hide' : function() {
			this.setTitle('增加一笔贷款');
			this.findById('debit.startdate').ownerCt.form.reset();
		}
	},
	items : [new Ext.FormPanel({
		border : false,
		baseCls : 'x-plain',
		bodyStyle : 'padding:5px 5px 0',
		labelAlign : 'right',
		labelWidth : 70,
		defaults : {anchor : '93%',msgTarget : 'side'},
		defaultType : 'textfield',
		items : [{
		   	xtype : 'combo',
			fieldLabel : '贷款人',
			name : 'loanid',
			hiddenName : 'debit.loanid',
			valueField : 'tid',
		    displayField : 'name',
		    mode : 'remote',
			store : ds_loan_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择贷款人',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('debit.loanname').setValue(record.data.name);
				},
				'expand' : function(){
					ds_loan_select.load();
				}
			}
		   }, {xtype : 'hidden',name : 'debit.loanname'}
		   , {
		   	xtype : 'datefield',
			fieldLabel : '贷款日期',
			id : 'debit.startdate',
			name : 'debit.startdate',
			format : 'Y-m-d',
			hiddenName : 'debit.startdate',
			allowBlank : false
		}, {
		   	xtype : 'datefield',
			fieldLabel : '到期日期',
			id : 'debit.closedate',
			name : 'debit.closedate',
			hiddenName : 'debit.closedate',
			format : 'Y-m-d',
			vtype:'dttypes',//自定义的验证类型
            vtypeText:'到期日期应该比贷款日期迟',
            confirmTo:'debit.startdate',//要比较的另外一个的组件的id
			allowBlank : false
		},{
		   	xtype : 'combo',
			fieldLabel : '存储帐号',
			name : 'cardnumber',
			hiddenName : 'debit.cardnumber',
			valueField : 'cardnumber',
		    displayField : 'cardnumber',
		    mode : 'remote',
			store : ds_account_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择存储帐号',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('debit.accountname').setValue(record.data.username);
					this.ownerCt.ownerCt.form.findField('debit.accountid').setValue(record.data.tid);
					this.ownerCt.ownerCt.form.findField('debit.debtorname').setValue(record.data.name);
					this.ownerCt.ownerCt.form.findField('debit.debtorid').setValue(record.data.owner);
				},
				'expand' : function(){
					ds_account_select.load();
				}
			}
		   },
		    {
		    fieldLabel : '账户开户人',
			id : 'debit.accountname',
			name : 'debit.accountname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',name : 'debit.accountid'}, 
		    {fieldLabel : '贷款单位',
			id : 'debit.debtorname',
			name : 'debit.debtorname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',name : 'debit.debtorid'}, 
		   {
		  	xtype:'numberfield',
		 	fieldLabel : '贷款金额',
		 	name : 'debit.csum',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '利率%',
		 	name : 'debit.rate',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '投资费用',
		 	name : 'debit.charge',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		   {xtype: 'textarea',
		   	fieldLabel : '备注',
		   name : 'debit.memo',
		   maxLength : 60
		   }
		],
		buttonAlign : 'right',
		minButtonWidth : 60,
		buttons : [{
			text : '添加',
			handler : function(btn) {
				var frm = this.ownerCt.ownerCt.form;
				if (frm.isValid()) {
					btn.disable();
					var unfield = frm.findField('debit.cardnumber');
					frm.submit({
						waitTitle : '请稍候',
						url : '/debit/saveDebit.action',
						waitMsg : '正在提交表单数据,请稍候...',
						success : function(form, action) {
							window_add_debit.hide();
							ds_debit.load({params : {start : 0,limit : 20}});
							btn.enable();
						},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '发生不明错误，请与管理员联系!',
								buttons : Ext.Msg.OK,
								fn : function() {
									unfield.focus(true);
									btn.enable();
								},
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			}
		}, {text : '重置',handler : function() {this.ownerCt.ownerCt.form.reset();}
		}, {text : '取消',handler : function() {
			this.ownerCt.ownerCt.ownerCt.hide();
			ds_debit.load({params : {start : 0,limit : 20}});
		}
		}]
	})]
});

var window_edit_debit = new Ext.Window({
	title : '修改贷款',
	width : 320,
	resizable : false,
	autoHeight : true,
	modal : true,
	closeAction : 'hide',
	listeners : {
		'hide' : function() {
			this.setTitle('修改贷款');
			this.findById('debitd.tid').ownerCt.form.reset();
		},
		'show' : function(){
			var record = grid_debit.getSelectionModel().getSelected();
			this.findById('debitd.tid').setValue(record.data.tid);
			this.findById('loanname').setValue(record.data.loanname);
			this.findById('debitd.cnumber').setValue(record.data.cnumber);
			this.findById('debitd.loanid').setValue(record.data.loanid);
			this.findById('debitd.startdate').setValue(renderDate(record.data.startdate));
			this.findById('debitd.closedate').setValue(renderDate(record.data.closedate));
			this.findById('cardnumber').setValue(record.data.cardnumber);
			this.findById('debitd.accountname').setValue(record.data.accountname);
			this.findById('debitd.accountid').setValue(record.data.accountid);
			this.findById('debitd.debtorname').setValue(record.data.debtorname);
			this.findById('debitd.debtorid').setValue(record.data.debtorid);
			this.findById('debitd.csum').setValue(record.data.csum);
			this.findById('debitd.rate').setValue(record.data.rate);
			this.findById('debitd.charge').setValue(record.data.charge);
			this.findById('debitd.memo').setValue(record.data.memo);
		}
	},
	items : [new Ext.FormPanel({
		border : false,
		baseCls : 'x-plain',
		bodyStyle : 'padding:5px 5px 0',
		labelAlign : 'right',
		labelWidth : 70,
		defaults : {anchor : '93%',msgTarget : 'side'},
		defaultType : 'textfield',
		items : [{xtype : 'hidden',id:'debitd.tid',name : 'debit.tid'},
			{ fieldLabel : '合同号',
			id : 'debitd.cnumber',
			name : 'debit.cnumber',
			allowBlank : false,
			readOnly :true,
			minLength : 5,
		 	maxLength : 32},
				{
		   	xtype : 'combo',
			fieldLabel : '贷款人',
			id:'loanname',
			name : 'loanname',
			hiddenName : 'debit.loanname',
			valueField : 'name',
		    displayField : 'name',
		    mode : 'remote',
			store : ds_loan_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择贷款人',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('debit.loanid').setValue(record.data.tid);
				},
				'expand' : function(){
					ds_loan_select.load();
				}
			}
		   }, {xtype : 'hidden',id:'debitd.loanid',name : 'debit.loanid'}
		   , {
		   	xtype : 'datefield',
			fieldLabel : '贷款日期',
			id : 'debitd.startdate',
			name : 'debit.startdate',
			format : 'Y-m-d',
			hiddenName : 'debit.startdate',
			allowBlank : false
		}, {
		   	xtype : 'datefield',
			fieldLabel : '到期日期',
			id : 'debitd.closedate',
			name : 'debit.closedate',
			hiddenName : 'debit.closedate',
			format : 'Y-m-d',
			vtype:'dttypes',//自定义的验证类型
            vtypeText:'到期日期应该比贷款日期迟',
            confirmTo:'debitd.startdate',//要比较的另外一个的组件的id
			allowBlank : false
		},{
		   	xtype : 'combo',
			fieldLabel : '存储帐号',
			id : 'cardnumber',
			name : 'cardnumber',
			hiddenName : 'debit.cardnumber',
			valueField : 'cardnumber',
		    displayField : 'cardnumber',
		    mode : 'remote',
			store : ds_account_select,
			selectOnFocus : true,
			editable : false,
			allowBlank : false,
			triggerAction : 'all',
			loadingText : '加载中...',
			emptyText : '请选择存储帐号',
			listeners : {
				'select' : function(combo, record, index) {
					this.ownerCt.ownerCt.form.findField('debit.accountname').setValue(record.data.username);
					this.ownerCt.ownerCt.form.findField('debit.accountid').setValue(record.data.tid);
					this.ownerCt.ownerCt.form.findField('debit.debtorname').setValue(record.data.name);
					this.ownerCt.ownerCt.form.findField('debit.debtorid').setValue(record.data.owner);
				},
				'expand' : function(){
					ds_account_select.load();
				}
			}
		   },
		    {
		    fieldLabel : '账户开户人',
			id : 'debitd.accountname',
			name : 'debit.accountname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',id:'debitd.accountid',name : 'debit.accountid'}, 
		    {fieldLabel : '贷款单位',
			id : 'debitd.debtorname',
			name : 'debit.debtorname',
			allowBlank : false,
			readOnly:true},
		    {xtype : 'hidden',id:'debitd.debtorid',name : 'debit.debtorid'}, 
		   {
		  	xtype:'numberfield',
		 	fieldLabel : '贷款金额',
		 	id:'debitd.csum',
		 	name : 'debit.csum',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '利率%',
		 	id:'debitd.rate',
		 	name : 'debit.rate',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '投资费用',
		 	id:'debitd.charge',
		 	name : 'debit.charge',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		   {xtype: 'textarea',
		   	fieldLabel : '备注',
		   	id:'debitd.memo',
		   name : 'debit.memo',
		   maxLength : 60
		   }
		],
		buttonAlign : 'right',
		minButtonWidth : 60,
		buttons : [{
			text : '保存',
			handler : function(btn) {
				var frm = this.ownerCt.ownerCt.form;
				if (frm.isValid()) {
					btn.disable();
					var unfield = frm.findField('debit.tid');
					frm.submit({
						waitTitle : '请稍候',
						url : '/debit/updateDebit.action',
						waitMsg : '正在提交表单数据,请稍候...',
						success : function(form, action) {
							window_edit_debit.hide();
							ds_debit.load({params : {start : 0,limit : 20}});
							btn.enable();
						},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '发生不明错误，请与管理员联系!',
								buttons : Ext.Msg.OK,
								fn : function() {
									unfield.focus(true);
									btn.enable();
								},
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			}
		},{text : '取消',handler : function() {
			this.ownerCt.ownerCt.ownerCt.hide();
			ds_debit.load({params : {start : 0,limit : 20}});
		}
		}]
	})]
});

var window_part_debit = new Ext.Window({
	title : '还款',
	width : 320,
	resizable : false,
	autoHeight : true,
	modal : true,
	closeAction : 'hide',
	listeners : {
		'hide' : function() {
			this.setTitle('还款');
			this.findById('hd.tid').ownerCt.form.reset();
		},
		'show' :function(){
			var record = grid_debit.getSelectionModel().getSelected();
			this.findById('hd.tid').setValue(record.data.tid);
			this.findById('hd.loanname').setValue(record.data.loanname);
			this.findById('hd.cnumber').setValue(record.data.cnumber);
			this.findById('hd.csum').setValue(record.data.csum);
			this.findById('hd.rate').setValue(record.data.rate);
			this.findById('hd.money').setValue(0);
			this.findById('hd.charge').setValue(0);
			
		}
	},
	items : [new Ext.FormPanel({
		border : false,
		baseCls : 'x-plain',
		bodyStyle : 'padding:5px 5px 0',
		labelAlign : 'right',
		labelWidth : 70,
		defaults : {anchor : '93%',msgTarget : 'side'},
		defaultType : 'textfield',
		items : [{xtype : 'hidden',id:'hd.tid',name : 'debit.tid'},
			{ fieldLabel : '合同号',
			id : 'hd.cnumber',
			name : 'debit.cnumber',
			allowBlank : false,
			readOnly :true,
			minLength : 5,
		 	maxLength : 32},
		 	{ fieldLabel : '贷款人',
			id : 'hd.loanname',
			name : 'debit.loanname',
			allowBlank : false,
			readOnly :true,
			minLength : 1,
		 	maxLength : 32},
		   {
		  	xtype:'numberfield',
		 	fieldLabel : '需还金额',
		 	id:'hd.csum',
		 	name : 'hd.csum',
		 	allowBlank : false,
		 	readOnly :true,
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '本次归还金额',
		 	id:'hd.money',
		 	name : 'debit.csum',
		 	allowBlank : false,
		 	vtype:'balance',//自定义的验证类型
            vtypeText:'超过所借的金额',
            confirmTo:'hd.csum',//要比较的另外一个的组件的id
		 	minLength : 1,
		 	maxLength : 12
		  },
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '调整利率%',
		 	id : 'hd.rate',
		 	name : 'debit.rate',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  }, {
		   	xtype : 'datefield',
			fieldLabel : '续借日期',
			id : 'hd.startdate',
			name : 'debit.startdate',
			format : 'Y-m-d',
			hiddenName : 'debit.startdate',
			allowBlank : false
		}, {
		   	xtype : 'numberfield',
			fieldLabel : '续借天数',
			id : 'hkttdays',
			name : 'ttdays',
			allowBlank : false,
			listeners : {
				'blur' : function(){
					var start = this.ownerCt.ownerCt.form.findField('debit.startdate').value;
					var ttd = this.value;
					if(ttd!=''){
						this.ownerCt.ownerCt.form.findField('debit.closedate').setValue(DateUtil.AddDayByDate(start,ttd));
					}
					
				}
			}
		}, {
		   	xtype : 'datefield',
			fieldLabel : '到期日期',
			id : 'hd.closedate',
			name : 'debit.closedate',
			hiddenName : 'debit.closedate',
			readOnly : true,
			editable : false,
			format : 'Y-m-d',
			allowBlank : false
		},
		  {
		  	xtype:'numberfield',
		 	fieldLabel : '投资费用',
		 	id : 'hd.charge',
		 	name : 'debit.charge',
		 	allowBlank : false,
		 	minLength : 1,
		 	maxLength : 12
		  },
		   {xtype: 'textarea',
		   	fieldLabel : '备注',
		   id : 'hd.memo',
		   name : 'debit.memo',
		   maxLength : 120
		   }
		],
		buttonAlign : 'right',
		minButtonWidth : 60,
		buttons : [{
			text : '还款',
			handler : function(btn) {
				var frm = this.ownerCt.ownerCt.form;
				if (frm.isValid()) {
					btn.disable();
					var unfield = frm.findField('hd.tid');
					frm.submit({
						waitTitle : '请稍候',
						url : '/debit/givebackPartDebit.action',
						waitMsg : '正在提交表单数据,请稍候...',
						success : function(form, action) {
							btn.enable();
							window_part_debit.hide();
							ds_debit.load({params : {start : 0,limit : 20}});
						},
						failure : function() {
							Ext.Msg.show({
								title : '错误提示',
								msg : '发生不明错误，请与管理员联系!',
								buttons : Ext.Msg.OK,
								fn : function() {
									unfield.focus(true);
									btn.enable();
								},
								icon : Ext.Msg.ERROR
							});
						}
					});
				}
			}
		},{text : '取消',handler : function() {
			this.ownerCt.ownerCt.ownerCt.hide();
			ds_debit.load({params : {start : 0,limit : 20}});
		}
		}]
	})]
});
var debit_Detail = new Ext.Panel({
    title: '详细内容'
});
var cm_debit_detail = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
	header : '合同号',
	width : 120,
	dataIndex : 'cnumber'
},{
	header : '贷款人',
	width : 80,
	dataIndex : 'loanname',
	sortable : false
},{
	header : '归还金额',
	width : 80,
	dataIndex : 'csum',
	sortable : false
},{
	header : '投资费用',
	width : 60,
	dataIndex : 'charge',
	renderer:renderDelay,
	sortable : true
},{
	header : '归还日期',
	width : 90,
	dataIndex : 'createtime',
	renderer: renderDate,
	sortable : true
}]);


var grid_debit_detail = new Ext.grid.GridPanel({
	title : '还贷纪录',
	iconCls : 'icon-grid',
	height: '100%',
	autoWidth : true,	   	   
	   	viewConfig:
	   	   {
	   	     forceFit:true,
	   	     scrollOffset:15
	   	    },	   	   
	autoScroll : true,
	loadMask : {msg : '数据加载中...'},
	cm : cm_debit_detail,
	ds : ds_debit_data,
	sm : new Ext.grid.RowSelectionModel({singleSelect : true}),
	enableColumnMove : false,
	trackMouseOver : false,
	frame : true
});
    
var debit_tabs=new Ext.TabPanel({
        activeTab:0,
        region: 'south',
        frame:true,
        items:[debit_Detail,grid_debit_detail]
 });
/* 
var p_debit = {
	id : 'debit-panel',
	border : false,
	layout : 'border',
	items : [grid_debit,debit_tabs]
};
*/

var debit_tabs2=new Ext.TabPanel({
        activeTab:0,
        defaults:{autoHeight: true},
        frame:true,
		collapsible: true,
		region: 'south',
        height: 150,
        minSize: 75,
        maxSize: 250,
        items:[debit_Detail,grid_debit_detail,{
        title: 'Tab 2',
        html: 'This is tab 2 content.'
    }]
 });

var p_debit = {
    id:'debit-panel',
    layout: 'border',
    bodyBorder: false,
    defaults: {
        split: true,
        animFloat: false,
        autoHide: false,
        useSplitTips: true,
		margins: '5 0 0 0',
        cmargins: '5 5 0 0',
    },
    items: [grid_debit,debit_tabs2]
};
